package com.ctsi.offlinesupport.service;

import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.organise.common.api.PersonServiceProxy;
import com.ctsi.organise.common.model.Person;
import com.ctsi.sms.client.SmsClient;
import com.ctsi.sms.entity.SmsEntity;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 触发发送消息通知
 * assignment 事件 触发
 * 王铎(18905456805)分配了支撑单，请及时支撑！
 * 2017053184420334的支撑单已支撑，请及时完成！
 * 王铎(18905456805)完成了支撑单，请及时评论！
 * 刘亮(18905444964)新增了支撑单，请及时分配！
 */
@Component("msgNotifyListener")
public class MsgNotifyListener implements TaskListener {


    @Autowired
    private PersonServiceProxy userServiceProxy;
//    @Autowired
//    private SmsMessageService smsMessageService;
    @Autowired
    private SmsClient smsClient;

    @Override
    public void notify(DelegateTask delegateTask) {
//        String key = delegateTask.getTaskDefinitionKey();

        // city-send-activity provincial-send-activity 政支主任派单
        // depart-role-send-activity 集成派单
        // supporting 支撑环节
        // initor-confirm 确认评价环节
        // assertLeader-activity 协助部门派单人
        // sid-CB0BCB31-C0E7-4363-A073-6D6130AE0B74 专家协助支撑

        String userId = delegateTask.getAssignee();
        SmsEntity sms = new SmsEntity();
        sms.setMlid(UUIDGenerator.getId());
        sms.setMlstate(0);
        sms.setCreated_at(System.currentTimeMillis());
        sms.setMlcontent("[政支在线]您有新的支撑单动态等待处理，请及时处理!");
        sms.setMltype("0");
        Person person = userServiceProxy.findPersonById(userId);
        sms.setPersonid(userId);
        sms.setPmoblie(person.getMobilePhone());
//        if ("city-send-activity".equals(key) || "provincial-send-activity".equals(key)) {
//        } else if ("depart-role-send-activity".equals(key)) {
//        } else if ("supporting".equals(key)) {
//        } else if ("initor-confirm".equals(key)) {
//        } else if ("assertLeader-activity".equals(key)) {
//        } else if ("sid-CB0BCB31-C0E7-4363-A073-6D6130AE0B74".equals(key)) {
//        }
//        smsClient.sendSMS(sms);
    }


}
